#!/user/bin/python
# -*- coding:utf-8 -*-
#filename:controllers/hotfeet.py


'''
从redis数据库获取hotfeet，组织成json返回

每日定时作业计算hotfeet存入redis

redis中zsets有序集合存储

Created on 2011-8-30

@author: zc


modify on 2011-09-12  none json--> {}

'''

from dbhandle import redisdb


"""从redis数据库获取热门tfeet并且返回json形式
  热门tfeet

    http://tinyfeet.us/i/hotfeet
    http://0.0.0.0:8080/i/hotfeet
   """
   
class hotfeet():
    def GET( self ):
        r = redisdb.redisdb( 1 )
        hotfeets = None
        thf = r.zrevrange( "hotfeet", 0, -1 )
        
        if thf:
            hotfeets = '{ "hotfeet":['
            for ht in thf:
                te = ht.split( ',' )
                hotfeets = hotfeets + '''{		
                                      "location" : "''' + te[0] + '''",
                                     "long" : "''' + str( te[1] ) + '''",
                               	      "lat" : "''' + str( te[2] ) + '''"
                               		},
                             		'''
            
            hotfeets = hotfeets[:-1]
            hotfeets.join( "]}" )
        else:
            hotfeets = "{}"
        
        print "[tfeet] hotfeet:", hotfeets
        
        return hotfeets


